
package com.bw.module_car.view

import android.content.Intent
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.bw.lib_base.path.RouterPath
import com.bw.lib_base.view.BaseActivity
import com.bw.module_car.R
import com.bw.module_car.adpter.CarAdapter
import com.bw.module_car.databinding.ActivityCarBinding
import com.bw.module_car.entity.CarEntity
import com.bw.module_car.viewmodel.CarViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlin.concurrent.thread

/**
 * 智慧园区-02-车位管理-v1.1-曲烨-20250509
 */
@Route(path = RouterPath.PATH_CAR_ACTIVITY)
@AndroidEntryPoint
class CarActivity : BaseActivity<ActivityCarBinding>() {

    private val vm by lazy { ViewModelProvider(this)[CarViewModel::class.java] }

    private lateinit var carAdapter: CarAdapter

    override fun initView() {
        carAdapter = CarAdapter()
        mDataBinding.carRv.layoutManager = LinearLayoutManager(this)


        vm.getCar()
        vm.getCarSuccess.observe(this){
            carAdapter.data.addAll(it)
            carAdapter.notifyDataSetChanged()
            mDataBinding.carRv.adapter = carAdapter
        }

        mDataBinding.addCar.setOnClickListener {
            startActivity(Intent(this,AddCarActivity::class.java))
        }


        carAdapter.addChildClickViewIds(R.id.car_repair,R.id.car_delete)

        carAdapter.setOnItemChildClickListener { adapter, view, position ->
            when(view.id){
                R.id.car_repair->{
                    startActivity(Intent(this,EditorCarActivity::class.java))
                }

                R.id.car_delete->{
                    carAdapter.notifyItemRemoved(position)

                }
            }
        }

        mDataBinding.imageView.setOnClickListener { finish() }


    }

    override fun getLayoutId(): Int {
        return R.layout.activity_car
    }


}